import axios from 'axios'
import cookie from 'js-cookie'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'


// 获取CSRF令牌
const csrftoken = cookie.get('csrftoken');
const requests = axios.create({
    baseURL: '/api',
    timeout: 5000,
    headers: {'X-CSRFToken': csrftoken},
})


requests.defaults.withCredentials = true
// 请求拦截器
requests.interceptors.request.use(function (value) {
        NProgress.start()
        return value
    }
)
// 响应拦截器
requests.interceptors.response.use((value => {
    NProgress.done();
    return value.data
}), error => {
    return error
})
export default requests